package com.xlp.snake.view;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

import org.w3c.dom.css.RGBColor;

import com.xlp.snake.entities.Food;
import com.xlp.snake.entities.Ground;
import com.xlp.snake.entities.Snake;
import com.xlp.snake.util.Global;

public class GamePanel extends JPanel{
	 
	 private Snake snake;
	 private Food food;
	 private Ground ground;
	
	 //显示
     public void display(Snake snake,Food food,Ground ground) {
    	 System.out.println("GamePanel's display");
    	 this.snake = snake;
    	 this.food = food;
    	 this.ground = ground;
    	 this.repaint(); //最终调用paintComponent()这个方法
     }

	@Override
	protected void paintComponent(Graphics g) {
		//  重新显示
		g.setColor(new Color(0x000000));
		g.fillRect(0, 0, Global.WIDTH * Global.CELL_SIZE, Global.HEIGHT * Global.CELL_SIZE);
		if(ground != null && snake != null && food != null) {
		this.ground.drawMe(g);
		this.snake.drawMe(g);
	    this.food.drawMe(g);
		}
	}
     
     
     
}
